home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 526 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.9 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: kanze@gabi.gabi-soft.fr (J. Kanze)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Time representations
  5. Date: 16 Feb 1996 09:04:41 PST
  6. Organization: GABI Software, Sarl.
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <KANZE.96Feb16125933@gabi.gabi-soft.fr>
  9. References: <4emq2k$ecu@news.duke.edu> <tuivhsd7fn.fsf@nemo.bedford.waii.com>
  10.     <4ere1v$mss@news.duke.edu> <4fddsi$md@hollywood.cinenet.net>
  11.     <4fovvr$f1d@blackice.winternet.com>
  12. NNTP-Posting-Host: isolde.mti.sgi.com
  13. X-Original-Date: 16 Feb 1996 11:59:33 GMT
  14. In-Reply-To: jdege@winternet.com's message of 13 Feb 1996 09:54:28 PST
  15. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  16.     iQBVAwUBMSS5UUy4NqrwXLNJAQEbVAH+JLCBxav/4dGDmBbuBQ4rtXtpoDjwv1Kp
  17.     Refbih7x1/mdPvQY4V/+cCG/hja3EqcjBL6y7sPf1pV3eNNN9vMtjA==
  18.     =SFvE
  19. Originator: austern@isolde.mti.sgi.com
  20.  
  21. In article <4fovvr$f1d@blackice.winternet.com> jdege@winternet.com (Jeff
  22. Dege) writes:
  23.  
  24. >     An off-the-wall question:
  25. > time() returns a time_t, localtime() converts this to a struct tm with
  26. > local time values, gmtime() converts this to a struct tm with GMT values,
  27. > mktime() converts this back to a time_t, but _which_ struct tm does
  28. > it convert back?
  29.  
  30. According to ISO 9899 (included by reference in the C++ standard): "The
  31. mktime function converts the broken-down time, expressed as
  32. _local_time_..."  (Emphesis added.)
  33.  
  34. > i.e.,
  35. > time_t t0 = time(NULL);
  36. > struct tm T1 = *localtime(&t0);
  37. > struct tm T2 = *gmtime(&t0);
  38. > time_t t1 = mktime(&T1);
  39. > time_t t2 = mktime(&T2);
  40. > Either t0 == t1 or t0 == t2, but which is true?
  41.  
  42. t0 == t1.
  43.  
  44. > Does the standard specify?
  45. > If so, how many compilers get it right?
  46.  
  47. Given that this is a standard C function, and has been around for a
  48. while, I would imagine that all of them do.  Particularly as the
  49. function author has to make a choice in the matter, and there is no
  50. particular motivation for a wrong choice.
  51.  
  52. More problematic is using mktime to correct the time, which it also
  53. supports.  For example:
  54.  
  55.     time_t          t0( time( NULL ) ) ;
  56.     struct tm       t = *localtime( &t0 ) ;
  57.     t.tm_min += 60 ;
  58.     mktime( &t ) ;
  59.  
  60. The last call to mktime should `correct' t so that the struct contains
  61. the correct entry for the time one hour after that returned by time.  I
  62. often wonder how well this has been tested, say when the original time
  63. was 10 minutes before midnight Dec. 31, or before a change in time due
  64. to switching between summer time and winter time.
  65. -- 
  66. James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
  67. GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
  68. Conseils, itudes et rialisations en logiciel orienti objet --
  69.               -- A la recherche d'une activiti dans une region francophone
  70. ---
  71. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  72.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy is
  73.   in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
  74.